package com.dreamwhale.machinery.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamwhale.machinery.user.entity.UserShop;
import com.dreamwhale.machinery.user.mapper.UserShopMapper;
import com.dreamwhale.machinery.user.service.UserShopService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 商户表 服务实现类
 * </p>
 *
 * @author Author
 * @since 2020-05-28
 */
@Service
public class UserShopServiceImpl extends ServiceImpl<UserShopMapper, UserShop> implements UserShopService {

    @Resource
    private UserShopMapper userShopMapper;

    @Override
    public List<UserShop> selectUserShopsLike(String merchantName, String provinceCode, String cityCode) {
        return userShopMapper.selectUserShopsLike(merchantName, provinceCode, cityCode);
    }

    @Override
    public List<UserShop> selectUserShopsLikeAsc(String merchantName, String provinceCode, String cityCode) {
        return userShopMapper.selectUserShopsLikeAsc(merchantName, provinceCode, cityCode);
    }

    @Override
    public UserShop selectUserShopMassage(Integer merId) {

        return userShopMapper.selectById(merId);
    }

    @Override
    public int insertUserShops(UserShop userShop) {
        userShop.setAddTime(LocalDateTime.now());
        return userShopMapper.insert(userShop);
    }

    @Override
    public int selectUserShopsCount(Integer userId) {
        QueryWrapper<UserShop> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_del", 0).notIn("status", -1).eq("uid", userId);
        List<UserShop> list = userShopMapper.selectList(queryWrapper);
        if (list.size() > 0) {
            return 1;
        }
        return 0;
    }
}
